package com.example.aigc_education.enums;

import com.example.aigc_education.common.BusinessException;
import lombok.Getter;

@Getter
public enum TodoCompletedType {
//    例如“complete”，“prepared”，或者用 0 和 1 表达待办的状态
    COMPLETE("complete", 1),
    PREPARED("prepared", 0);

    private final String title;
    private final Integer value;

    TodoCompletedType(String title, Integer value) {
        this.title = title;
        this.value = value;
    }

    public static TodoCompletedType fromTitle(String title) {
        for (TodoCompletedType type : TodoCompletedType.values()) {
            if (type.title.equals(title)) {
                return type;
           }
        }
        throw new BusinessException("Invalid title: " + title);
    }

    public static TodoCompletedType fromValue(Integer value) {
        for (TodoCompletedType type : TodoCompletedType.values()) {
            if (type.value.equals(value)) {
                return type;
            }
        }
        throw new BusinessException("Invalid value: " + value);
    }
}

